import pyautogui

def find_and_perform_action(hwnd, model, target_class, action):
    from 检测框模块 import get_window_screenshot
    # 获取窗口截图
    screenshot = get_window_screenshot(hwnd)
    # 进行目标检测
    results = model(screenshot)
    # 检查是否找到目标类
    found_target = False
    for result in results:
        boxes = result.boxes.cpu().numpy()
        for box in boxes:
            class_id = int(box.cls[0])
            if class_id == target_class:
                found_target = True
                break
        if found_target:
            break
    # 如果找到目标类，执行动作
    if found_target:
        action()

    # 按下 F9
    pyautogui.hotkey('f9')